home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Texto y fuentes / BoldAndItalic / BoldAndItalic.cs next >
Encoding:
Text File  |  2002-04-24  |  1.7 KB  |  47 lines

  1. //--------------------------------------------
  2. // BoldAndItalic.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class BoldAndItalic: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new BoldAndItalic());
  13.      }
  14.      public BoldAndItalic()
  15.      {
  16.           Text = "Texto en negrita y cursiva";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           const string str1        = "Este es un texto en ";
  21.           const string str2        = "negrita";
  22.           const string str3        = " y este es un texto en ";
  23.           const string str4        = "cursiva";
  24.           const string str5        = ".";
  25.           Brush        brush       = new SolidBrush(clr);
  26.           Font         fontRegular = Font;
  27.           Font         fontBold    = new Font(fontRegular, FontStyle.Bold);
  28.           Font         fontItalic  = new Font(fontRegular, FontStyle.Italic);
  29.           float        x           = 0;
  30.           float        y           = 0;
  31.  
  32.           grfx.DrawString(str1, fontRegular, brush, x, y);
  33.           x += grfx.MeasureString(str1, fontRegular).Width;
  34.  
  35.           grfx.DrawString(str2, fontBold, brush, x, y);
  36.           x += grfx.MeasureString(str2, fontBold).Width;
  37.  
  38.           grfx.DrawString(str3, fontRegular, brush, x, y);
  39.           x += grfx.MeasureString(str3, fontRegular).Width;
  40.  
  41.           grfx.DrawString(str4, fontItalic, brush, x, y);
  42.           x += grfx.MeasureString(str4, fontItalic).Width;
  43.  
  44.           grfx.DrawString(str5, fontRegular, brush, x, y);
  45.      }
  46. }
  47.